package com.coocaa.typhoon.api.third.volcengine.service;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.coocaa.cirrus.common.base.util.JsonUtil;
import com.coocaa.cirrus.common.base.util.RetryUtil;
import com.coocaa.typhoon.api.third.volcengine.model.VikingDbUserFileEntity;
import com.coocaa.typhoon.api.third.volcengine.model.output.UserFileVO;
import com.coocaa.typhoon.api.third.volcengine.util.VikingDbConvert;
import com.coocaa.typhoon.api.v1.userfile.model.input.GetSearchDataModel;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
import com.volcengine.service.vikingDB.CollectionClient;
import com.volcengine.service.vikingDB.IndexClient;
import com.volcengine.service.vikingDB.VikingDBService;
import com.volcengine.service.vikingDB.common.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author bijiahao
 * @date : 2025/9/18 14:21
 * @description
 */
@Slf4j
@Service
public class VikingDbMgrService {
    @Autowired
    private VikingDBService vikingDBService;

    public Map<String, Object> embeddingV2(String tosUrl) {
        try {
            HashMap<String, Object> params = new HashMap<>();
            params.put("return_token_usage", true);
            ArrayList<RawData> rawDatas = new ArrayList<>();
            rawDatas.add(new RawData().setDataType("image").setImage(tosUrl).build());
            Map<String, Object> res = vikingDBService.embeddingV2(new EmbModel().setModelName("doubao-embedding-vision").setParams(params).build(), rawDatas);
            return res;
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }
    }

    public Map<String, Object> queryTextVector(String text) {
        try {
            HashMap<String, Object> params = new HashMap<>();
            params.put("return_token_usage", true);
            ArrayList<RawData> rawDatas = new ArrayList<>();
            rawDatas.add(new RawData().setDataType("text").setText(text).build());
            Map<String, Object> res = vikingDBService.embeddingV2(new EmbModel().setModelName("doubao-embedding-large-and-m3").setParams(params).build(), rawDatas);
            return res;
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }
    }
}
